<?php
require_once('../../config.php');
Doctrine::loadModels('../../models');

if ($_REQUEST["agent_id"]) 
{
	$agent_id = strip_tags($_REQUEST["agent_id"]);
	
	$query = $db_query = sprintf("SELECT am.message_id, am.agent_id, am.subject_id, am.title, am.rating_id, 
		am.message, am.message_is_public, am.message_is_comment, am.parent_message_id,
		am.created, am.modified, am.created_by, am.modified_by, s.item_name subject, r.item_name rating  
	FROM agent_message am
  		INNER JOIN lk_glossary s ON am.subject_id = s.item_id
  		INNER JOIN lk_glossary r ON am.rating_id = r.item_id
	WHERE am.agent_id ='".$agent_id."'");
	
	$items = mysql_query($query);
    
    //file_put_contents  ( "getMessage.txt", $query);
}

$dom = new DomDocument('1.0',"UTF-8");
$dom->formatOutput = true;
$root = $dom->createElement( "results" );
$dom->appendChild( $root );
	while(($item = mysql_fetch_assoc($items)))
	{
		$dn = $dom->createElement( "record" );
		$dn->setAttribute( 'message_id', $item['message_id'] );
		$dn->setAttribute( 'parent_message_id', $item['parent_message_id'] );
		$dn->setAttribute( 'agent_id', $item['agent_id'] );
		$dn->setAttribute( 'subject_id', $item['subject_id'] );
		$dn->setAttribute( 'title', $item['title'] );
		$dn->setAttribute( 'subject', $item['subject'] );
		$dn->setAttribute( 'rating_id', $item['rating_id'] );
		$dn->setAttribute( 'rating', $item['rating'] );
		$dn->setAttribute( 'message_is_public', $item['message_is_public'] );
		$dn->setAttribute( 'message_is_comment', $item['message_is_comment'] );
		$dn->setAttribute( 'message', ($item['message']));
		$dn->setAttribute( 'created', ($item['created']));
		$dn->setAttribute( 'modified', ($item['modified']));
		$root->appendChild( $dn );
}		

header( "Content-type: text/xml; charset=UTF-8" );
echo $dom->saveXML();


?>
	
